package array_AI;


class Player {
    String name;
    int index;

    Player(String name, int index) {
        this.name = name;
        this.index = index;
    }

    @Override
    public String toString() {
        return "Player{" +
                "name='" + name + '\'' +
                ", index=" + index +
                '}';
    }
}

public class Array_AI {
	    public static void main(String[] args) {
	        int n = 7; // 总人数
	        int k = 3; // 每数到k的人出列
	        int startIndex = 0; // 从第0个开始计数

	        Player[] players = new Player[n];
	        for (int i = 0; i < n; i++) {
	            players[i] = new Player("Player" + (i + 1), i + 1);
	        }

	        int currentIndex = startIndex;
	        int remainingPlayers = n;

	        while (remainingPlayers > 1) {
	            // 找到下一个要移除的玩家
	            currentIndex = (currentIndex + k - 1) % remainingPlayers;
	            System.out.println("Removing: " + players[currentIndex]);

	            // 将剩余的玩家向前移动
	            for (int i = currentIndex; i < remainingPlayers - 1; i++) {
	                players[i] = players[i + 1];
	            }
	            remainingPlayers--;
	        }

	        System.out.println("Last remaining player: " + players[0]);
	    }
	}

